import Request from "@/sdk/pocky-request/index.js"; //引入
/**
 * shopStore 店铺模块
 */
const shop = {
	// 状态
	state: {

	},
	// 内部派生
	getters: {

	},
	// 同步方法 commit
	mutations: {

	},
	// 异步方法 dispatch
	actions: {
		/**
		 * @description 获取店铺详情
		 * @param {Object} context
		 * @param {Object} _id
		 */
		apiGetShopDetail(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/store/detail.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取店铺详情失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: JSON.stringify(err),
						icon: 'none'
					});
				})
			})
		},
		/**
		 * @description 根据教师ID获取教师详情
		 * @param {Object} context
		 * @param {Object} _id
		 */
		apiGetTeacherDtById(context, _id) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '',
					method: 'post',
					data: {
						id: _id
					}
				}).then(res => {
					if (res.data.code == 1) {

					} else {
						uni.showToast({
							title: '获取教师详情失败,' + res.data.msg,
							icon: 'none'
						});
					}
				}).catch(err => {
					uni.showToast({
						title: JSON.stringify(err),
						icon: 'none'
					});
				})
			})
		},
		/**
		 * 获取活动列表
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetGroupList(context, _data) {
			return new Promise(resolve => {
				let r = Request();
				r.request({
					url: '/group/course/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)

					} else {
						// uni.showToast({
						// 	title: '添加店铺失败,'+res.data.msg,
						// 	icon: 'none'
						// });
					}
				})

			})
		},
		/**
		 * @description 获取活动详情
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetGroupDetail(context, _data) {
			return new Promise(resolve => {
				let r = Request();
				r.request({
					url: '/group/course/detail.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)

					} else {
						// uni.showToast({
						// 	title: '添加店铺失败,'+res.data.msg,
						// 	icon: 'none'
						// });
					}
				})

			})
		},
		/**
		 * @description  开团
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiOpenGroup(context, _data) {
			return new Promise(resolve => {
				let r = Request();
				r.request({
					url: '/group/open.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)

					} else {
						uni.showToast({
							title: '开团失败,' + res.data.msg,
							icon: 'none'
						});
					}
				})

			})
		},
		/**
		 * @description 获取我的拼团列表
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetMyGroupList(context, _data) {
			return new Promise(resolve => {
				let r = Request();
				r.request({
					url: '/group/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)

					} else {
						uni.showToast({
							title: '获取拼团失败,' + res.data.msg,
							icon: 'none'
						});
						resolve([])
					}
				})

			})
		},
		/**
		 * @description 获取我的拼团详情
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetMyGroupDt(context, _data) {
			return new Promise(resolve => {
				let r = Request();
				r.request({
					url: '/group/detail.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)

					} else {
						uni.showToast({
							title: '获取拼团详情失败,' + res.data.msg,
							icon: 'none'
						});
						resolve([])
					}
				})

			})
		},
		/**
		 * 关注店铺
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiFollowShop(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/store/fav.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.result == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {
					reject(res)
				})
			})
		},
		/**
		 * @description 生成口令
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetPass(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/group/genToken.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1 ||res.data.result==1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		// (#.*?#)

		/**
		 * 解析口令
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiResolvePass(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/group/getToken.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**
		 * @description  获取团长奖励
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetCmdRew(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/group/award/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**
		 * 获取拼团返现
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetGroupReturn(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/group/refund/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**获取提现记录
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetTxHis(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/group/fetch/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**
		 * @description 获取零元购活动列表
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetZeroList(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/zero/course/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**
		 * @description 获取零元购活动详情
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetZeroDetail(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/zero/course/detail.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**
		 * @description 提交零元购订单
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiPostZeroOrder(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/mall/order.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						reject(res);
					}
				}).catch(err => {

					reject(res)
				})
			})
		}
	}
}

export default shop
